package org.springframework.uuu;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanMetadataAttribute;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;

import java.lang.reflect.GenericDeclaration;

public class Main {

	public static void main(String[] args)
	{
		GenericBeanDefinition dog = new GenericBeanDefinition();
		dog.setBeanClassName("org.springframework.uuu.User");
		BeanMetadataAttribute age = new BeanMetadataAttribute("age","3");
		dog.addMetadataAttribute(age);

		// 子Definition的创建需要依赖父Definition
		ChildBeanDefinition teddy = new ChildBeanDefinition("dog");
		teddy.setBeanClassName("org.springframework.uuu.CompanyUser");
		BeanMetadataAttribute name = new BeanMetadataAttribute("name","doudou");
		teddy.addMetadataAttribute(name);
		System.out.println("----------------------------");
		System.out.println(dog);
		System.out.println("Hello World!");

		GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
		beanDefinition.setBeanClassName("org.springframework.uuu.CompanyUser");
		beanDefinition.setLazyInit(false);
		// 创建一个MutablePropertyValues
		MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
		mutablePropertyValues.add("name", "ydl");
		mutablePropertyValues.add("age", 18);
		beanDefinition.setPropertyValues(mutablePropertyValues);
		System.out.println(beanDefinition);

		RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
		rootBeanDefinition.overrideFrom(beanDefinition);
		System.out.println("----------------------------");
		System.out.println(rootBeanDefinition);
		System.out.println("Hello World!");
	}
}
